/**
 * 
 */
package com.appspot.yttv.client;

import java.util.ArrayList;
import java.util.List;

import com.google.gwt.user.client.ui.Label;

/**
 * @author Richard Tucker
 * A class for debug logging.
 */

public class Console {
	private static Label label;
	private static List<String> text = new ArrayList<String>();
	private static boolean visible;
	private static int ROWS = 48;

	public static Label init() {
		label = new Label();
		hide();
		log("Console inited.");
		return label;
	}
	public static void hide() {
		visible = false;
		restyle();
	}
	public static void show() {
		visible = true;
		restyle();
	}
	public static void toggle() {
		visible = !visible;
		restyle();
	}
	private static void restyle() {
		if (visible) {
			label.setStyleName("console");			
		} else {
			label.setStyleName("console_hidden");
		}
	}
	public static void log(String s) {
		text.add(s);
		if (text.size() > ROWS) {
			text.remove(0);
		}
		if (label != null) {
		   StringBuffer buffer = new StringBuffer();
		   for (String line: text) {
			   buffer.append(line + "\n");
		   }
		   label.setText(buffer.toString());
		}
	}
}
